const fs=require('fs')
const path=require('path')
// 1. 导入 http 模块
const http = require('http')

// 2. 创建 web 服务器实例
const server = http.createServer()

// 3. 启动服务器
server.listen(9999, () => {
  console.log('my server start work')
})

// 4. 为服务器实例绑定 request 事件，监听客户端的请求
server.on('request', (request, response) => {
    const fullPath=path.join(__dirname,'./lucystar/db/data/info.json')
    const data=fs.readFileSync(fullPath,'utf-8')
    //  data=JSON.parse(data)
    console.log(data);
    response.setHeader('Content-Type', 'application/json; charset=utf-8')
    response.setHeader('Access-Control-Allow-Origin', '*')
    if (request.url==='/api/info'&& request.method==='GET') {
        response.end(data)
    }
})
